home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
tools
/
zmc3v078
/
zmc3v078.lzh
/
SRCSV078.LZH
/
MAKEZMD3.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-02-27
|
49KB
|
1,721 lines
/* ==========================================
@ series (@v, @b, @r, ... ) conversion
and... many subroutines
========================================== */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "etc.h"
#include "makezmd2.h"
#include "parsesub.h"
#include "velo.h"
#include "68lib.h"
#include "arcc.h"
#include "bracket.h"
#include "structs.h"
#include "structs2.h"
int checkInternalDevice(TRKCHINF *trkdata, BYTE Trk);
void initTrkInf(TRKINF *trkinf, COMMONINF *cominf);
void initTrkInf2(TRKINF *trkinf, int trk);
void freeTrkInf(TRKINF *trkinf,int trk);
void copyTrkInf(TRKINF *des, TRKINF *src);
UBYTE *makeZmdAtmark(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf,COMMONINF *cominf);
UBYTE *makeZmdLoop1(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf);
UBYTE *makeZmdEigDepthSub(UBYTE *zms,
VELOETCVAR *vv, BYTE *pos,BYTE *num,BYTE supplementmode);
UBYTE *makeZmdVeloSeq(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf);
UBYTE *makeZmdQuantize(UBYTE *zms, int mode, const BYTE target[],
TRKINF *trkinf);
UBYTE *makeZmdManyParas(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
DWORD line_,char *linebuf,
UBYTE com, UBYTE omitcode,BYTE maxparas,
BYTE parabytes,BYTE omitflg,
char *errmes1, char *errmes2,char *errmes3);
UBYTE *makeZmdManyParas2(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
DWORD line_,char *linebuf_,
UBYTE com, BYTE maxparas,
const BYTE parabytes[],BYTE omitflg,BYTE ARCCno,
int space, int times,const int mustover0,
char *errmes1, char *errmes2,char *errmes3);
UBYTE *makeZmdManyParas2A(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
DWORD line_,char *linebuf_,
UBYTE com, BYTE maxparas,
const BYTE parabytes[],BYTE omitflg, BYTE ARCCno,
int mode,
char *errmes1, char *errmes2,char *errmes3);
UBYTE *makeZmdChord(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf,char extmode,COMMONINF *cominf);
CHKCHORD *addNextChkChord(CHKCHORD *c, BYTE note, DWORD gate, DWORD total);
void rewriteGateinChord(TRKCHINF *trkdata, TRKINF *trkinf,
int Trk,CHKCHORD *c, UWORD gate);
CHKCHORD *killChord(CHKCHORD *c);
UBYTE *makePortament(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf,COMMONINF *cominf,const char endchar);
int checkCommonCommand(UBYTE *zms_,int notes,BYTE note[],UWORD step_,
DWORD line_,char *linebuf_, COMMONINF *cominf);
extern DWORD line;
extern char *linebuf;
extern LINEDATA *ld;
int checkInternalDevice(TRKCHINF *trkdata, BYTE Trk) { /* thanks to Mamiya */
if (trkdata[Trk].chtype == 0) return 1; /* OPM */
if (trkdata[Trk].chtype == 1) return 2; /* ADPCM */
#ifdef A
if (25 <= trkdata[Trk].ch && trkdata[Trk].ch <= 31) return 2; /* PCM8 */
#endif
return 0 ; /* MIDI */
}
void initTrkInf(TRKINF *trkinf, COMMONINF *cominf)
{
int j;
trkinf->total = 0;
trkinf->noteon = 0;
trkinf->setdev = 0;
trkinf->volmode = 0; /* 128 mode */
trkinf->velocity = (VELOETCVAR*)emalloc(sizeof(VELOETCVAR) * 1,"trkinf->velocity");
trkinf->velocity[0].var[0] = 127;
trkinf->velocity[0].var[1] = 0;
trkinf->velozpos = 0;
trkinf->veloznum = 0;
trkinf->velou.var[0] = 127;
trkinf->velou.var[1] = 0;
trkinf->velou.relflg[0] = 0; /* velocity sequences flag: 1:now on use 0: non use */
trkinf->relvelo = 0;
trkinf->nowvelo = 127;
trkinf->veloseqsw = 1;
trkinf->mod[0].var[0] = 0;
trkinf->arcc[0].var[0] = 127;
trkinf->mod[0].relflg[0] = 0;
trkinf->arcc[0].relflg[0] = 0;
trkinf->volofst = 0;
trkinf->veloofst = 0;
trkinf->arccofst[0] = trkinf->arccofst[0] =
trkinf->arccofst[0] = trkinf->arccofst[0] = 0;
trkinf->gtreso = cominf->gtreso;
trkinf->quantize = (VELOETCVAR*)emalloc(sizeof(VELOETCVAR) * 1,"trkinf->quantize");
trkinf->quantize[0].var[0] = cominf->gtreso;
trkinf->quantize[0].relflg[0] = 0;
trkinf->quantize[0].relflg[1] = -1;
trkinf->quantizepos = 0;
trkinf->quantizenum = 1;
trkinf->octave = 4;
trkinf->Step = 48;
trkinf->laststep = 48;
trkinf->velozpos = 0;
trkinf->veloznum = 0;
trkinf->modpos = 0;
trkinf->modnum = 0;
trkinf->arccpos = 0;
trkinf->arccnum = 0;
/* trkinf->vol = 64; */
trkinf->relvol = 1;
trkinf->randvelotype = 0;
trkinf->randvelopower = 0;
for (j = 0; j < 12; j++) {
trkinf->ksign[j] = 0;
}
trkinf->transpose = 0;
trkinf->fadeout = 0;
trkinf->abdelay = 0;
trkinf->pdelay = 0;
trkinf->cdelay = 0;
trkinf->ptime = 0;
trkinf->spvelomode = 0;
trkinf->renpnotes = 0;
trkinf->cominf = cominf;
trkinf->segno = 0;
trkinf->coda = 0;
trkinf->back_repeat = 0;
trkinf->bankh = trkinf->bankh = 0;
trkinf->echoitv = 0;
trkinf->echodec = 0;
trkinf->echolp = 1;
}
void initTrkInf2(TRKINF *trkinf, int trk)
{
char s[32];
sprintf(s,"trkinf[%d]->l_initTrkInf2",trk);
trkinf->l = (LOOPDATA*)emarealloc( trkinf->l, sizeof(LOOPDATA) * 1,s);
sprintf(s,"trkinf[%d]->d_initTrkInf2",trk);
trkinf->d = (LOOPDATA*)emarealloc( trkinf->d, sizeof(LOOPDATA) * 1,s);
sprintf(s,"trkinf[%d]->r_initTrkInf2",trk);
trkinf->r = (RENP*)emarealloc( trkinf->r, sizeof(RENP) * 1,s);
sprintf(s,"trkinf[%d]->s_initTrkInf2",trk);
trkinf->s = (CHKSTEP*)emarealloc( trkinf->s, sizeof(CHKSTEP) * 1,s);
sprintf(s,"trkinf[%d]->c_initTrkInf2",trk);
trkinf->c = (CHKCHORD*)emarealloc( trkinf->c, sizeof(CHKCHORD) * 1,s);
#ifdef A
trkinf->l = (LOOPDATA*)emalloc(sizeof(LOOPDATA) * 1,"trkinf->l");
trkinf->d = (LOOPDATA*)emalloc(sizeof(LOOPDATA) * 1,"trkinf->d");
trkinf->r = (RENP*)emalloc(sizeof(RENP) * 1,"trkinf->r");
trkinf->s = (CHKSTEP*)emalloc(sizeof(CHKSTEP) * 1,"trkinf->s");
#endif
/*
trkinf->b = (BACK*)emalloc(sizeof(BACK) * 1);
trkinf->e = (EVENT*)emalloc(sizeof(EVENT) * 1);
*/
trkinf->l->next = trkinf->l->prev = NULL;
trkinf->l->loopmode = 0;
trkinf->d->next = trkinf->d->prev = NULL;
trkinf->d->looptime = 0;
trkinf->r->next = trkinf->r->prev = NULL;
trkinf->s->next = trkinf->s->prev = NULL;
trkinf->c->next = trkinf->c->prev = NULL;
/*
trkinf->b->next = trkinf->b->prev = NULL;
trkinf->e->next = trkinf->e->prev = NULL;
*/
trkinf->r->step = -1;
trkinf->r->pflg = 0;
trkinf->s->step = 0;
trkinf->c->note = -1;
trkinf->c->gatepos = -1;
/*
trkinf->e->code = 0;
*/
}
void freeTrkInf(TRKINF *trkinf, int trk)
{
char s[32];
sprintf(s,"trkinf[%d]->velocity",trk);
efree(trkinf->velocity,s);
trkinf->velocity = NULL;
sprintf(s,"trkinf[%d]->quantize",trk);
efree(trkinf->quantize,s);
trkinf->quantize = NULL;
sprintf(s,"trkinf[%d]->l",trk);
efree(trkinf->l,s);
trkinf->l = NULL;
sprintf(s,"trkinf[%d]->d",trk);
efree(trkinf->d,s);
trkinf->d = NULL;
sprintf(s,"trkinf[%d]->r",trk);
efree(trkinf->r,s);
trkinf->r = NULL;
sprintf(s,"trkinf[%d]->s",trk);
efree(trkinf->s,s);
trkinf->s = NULL;
sprintf(s,"trkinf[%d]->c",trk);
efree(trkinf->c,s);
trkinf->c = NULL;
/*
free(trkinf->b);
free(trkinf->e);
*/
}
void copyTrkInf(TRKINF *des, TRKINF *src)
{
int i;
BYTE num;
efree(des->velocity,"des->velocity");
efree(des->quantize,"des->quantize");
{
LOOPDATA *l, *d;
RENP *r;
CHKSTEP *s;
CHKCHORD *c;
l = des->l;
d = des->d;
r = des->r;
s = des->s;
c = des->c;
*des = *src;
des->l = l;
des->d = d;
des->r = r;
des->s = s;
des->c = c;
}
num = des->veloznum ? des->veloznum : 1;
des->velocity = emalloc(sizeof(VELOETCVAR) * num,"des->velocity");
for (i = 0; i < num; i++) {
des->velocity[i] = src->velocity[i];
}
num = des->quantizenum ? des->quantizenum : 1;
des->quantize = emalloc(sizeof(VELOETCVAR) * num,"des->quantize");
for (i = 0; i < num; i++) {
des->quantize[i] = src->quantize[i];
}
}
UBYTE *makeZmdAtmark(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf,COMMONINF *cominf)
{
UBYTE *zms_ = zms + 1;
DWORD tmpDWORD;
int trk,err;
DWORD line_ = line;
char *linebuf_ = linebuf;
LINEDATA *ld_ = ld;
switch (*zms++) {
case 'a': case 'A': /* @a */
zms = makeARCClevel0(zms, trkdata, target, trkinf, 0, -2);
break;
case 'b': case 'B': /* @b */
zms = makeZmdBend(zms, trkdata, trkinf, target, 1);
break;
case 'c': case 'C': /* @c */
{
const BYTE parabytes[3] = {1,1,1};
zms = makeZmdManyParas2A(zms,trkdata,target,line_,linebuf_,
0xF7, 3, parabytes, 1, 0, -1,
"@c: too many parameters.",
"@c can't use relational parameters.",
"");
}
break;
case 'd': case 'D': /* @d */
/*OK*/ zms = makeZmdDamper(zms, trkdata, target, 0);
break;
case 'e': case 'E': /* @e */
/*OK*/ zms = makeZmdEffect(zms,trkdata,target);
break;
case 'g': case 'G': /* @g */
/*OK*/ zms = makeZmdBendRange(zms, trkdata, target);
break;
case 'h': case 'H': /* @h */
/*OK*/
{
UBYTE cmd[] = {0xE4, 0xE7};
int i;
for (i = 0; i < 2; i++) {
int err;
DWORD p;
zms = getnum2(zms, &p, &err);
if (err > 0) {
zmserror("@H parameter error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = cmd[i];
if (i == 1) {
*trkdata[Trk].zmd++ = 0;
}
putWord(trkdata[Trk].zmd, 1);
putWord(trkdata[Trk].zmd + 2, p);
trkdata[Trk].zmd += 4;
}
}
zms = skipSpc(zms);
if (*zms == ',') {
zms += 1;
} else {
break;
}
}
}
break;
case 'i': case 'I': /* @i */
/*OK*/ {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
trkinf[target[trk]].setdev = 1;
}
}
zms = makeZmdInstrumentId(zms,trkdata,target);
break;
case 'j': case 'J': /* @j */
/*OK*/ zms = makeZmdTieMode(zms, trkdata, target);
break;
case 'k': case 'K': /* @k */
zms = makeZmdBend(zms, trkdata, trkinf, target, 0);
break;
case 'l': case 'L': /* @l */
/*OK*/ zms = getnum2(zms_, &tmpDWORD, &err);
if (err < 0) {
zmserror("@l can't omit its parameter.",line_,linebuf_,zms_,0,1);
}
for (trk = 0; target[trk] >= 0; trk++) {
trkinf[target[trk]].Step = tmpDWORD;
}
break;
case 'm': case 'M': /* @m */
for (trk = 0; target[trk] >= 0; trk++) {
int i;
VELOETCVAR v[17];
const int Trk = target[trk];
line = line_;
ld = ld_;
zms = makeZmdEigDepthSub(zms_,
v,&trkinf[Trk].modpos,
&trkinf[Trk].modnum,1);
if (trkinf[Trk].modnum == 0) {
/*OK*/ *trkdata[Trk].zmd++ = 0xE2; /* mod sw off */
*trkdata[Trk].zmd++ = 0x00;
*trkdata[Trk].zmd++ = 0x00;
} else if (trkinf[Trk].modnum == 1) {
/*OK*/
#ifdef A
/* if (v[0].var[0] == 0) { */
*trkdata[Trk].zmd++ = 0xE2; /* mod sw off */
*trkdata[Trk].zmd++ = 0x00;
*trkdata[Trk].zmd++ = 0x00;
/* } else { */
#endif
*trkdata[Trk].zmd++ = 0xE2; /* mod single */
*trkdata[Trk].zmd++ = 0x01;
*trkdata[Trk].zmd++ = 0x01;
putWord(trkdata[Trk].zmd, v[0].var[0]);
trkdata[Trk].zmd += 2;
/* } */
} else { /* mod dep1/8 */
/*OK*/ UBYTE *zmd__;
UBYTE flg = 0;
*trkdata[Trk].zmd++ = 0xE2;
*trkdata[Trk].zmd++ = 0xFF;
zmd__ = trkdata[Trk].zmd;
trkdata[Trk].zmd++;
for (i = 0; i < trkinf[Trk].modnum; i++) {
trkinf[Trk].mod[i].var[0] = v[i].var[0];
trkinf[Trk].mod[i].relflg[0] = v[i].relflg[0];
flg >>= 1;
if (v[i].relflg[0] != 2) {
putWord(trkdata[Trk].zmd,v[i].var[0]);
trkdata[Trk].zmd += 2;
flg |= 0x80;
}
#ifdef A
if (v[i].relflg[0] != 2) {
flg |= 0x80;
}
#endif
}
for (i = trkinf[Trk].modnum; i < 8; i++) {
trkinf[Trk].mod[i].var[0] = 0;
trkinf[Trk].mod[i].relflg[0] = 2;
/*
putWord(trkdata[Trk].zmd,0);
trkdata[Trk].zmd += 2;
*/
flg >>= 1;
flg &= 0x7F;
}
*zmd__ = flg;
}
}
break;
case 'n': case 'N': /* @n : channel change */
/*OK*/ zms = getnum2(zms, &tmpDWORD, &err);
if (err < 0) {
zmserror("@n can't omit its parameter.",line_,linebuf_,zms_,0,1);
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
UWORD dev,ch;
if (tmpDWORD <= 8) {
dev = 0;
ch = tmpDWORD;
} else if (tmpDWORD == 9) {
dev = 1;
ch = 0;
} else if (tmpDWORD <=25) {
dev = 0x8000;
ch = tmpDWORD - 10;
} else if (tmpDWORD < 32) {
dev = 1;
ch = tmpDWORD - 26 + 1;
} else {
dev = 0x8000 + (tmpDWORD - 33) / 16;
ch = (tmpDWORD - 33) % 16;
}
*trkdata[Trk].zmd++ = 0xCC;
putWord(trkdata[Trk].zmd, dev);
putWord(trkdata[Trk].zmd + 2, ch);
trkdata[Trk].zmd += 4;
if (trkinf[Trk].noteon) {
trkdata[Trk].chtype = dev;
trkdata[Trk].ch = ch;
}
}
break;
case 'p': case 'P': /* @p */
zms = makeZmdPanpot(zms, trkdata, target, 0);
break;
case 'q': case 'Q': /* @q */
/*ok*/ zms = makeZmdQuantize(zms, 0, target, trkinf);
break;
case 'r': case 'R': /* @r */
/*OK*/ zms = makeZmdTrackMode(zms, trkdata, trkinf, target);
break;
case 's': case 'S': /* @s */
/*OK*/
{
UBYTE cmd[] = {0xE3, 0xE6};
int i;
for (i = 0; i < 2; i++) {
int err;
DWORD p;
zms = getnum2(zms, &p, &err);
if (err > 0 || (err == 0 && p == 0)) {
zmserror("@S parameter error.",line,linebuf,zms,0,1);
} else if (!err) {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = cmd[i];
if (i == 1) {
*trkdata[Trk].zmd++ = 0x00;
}
*trkdata[Trk].zmd++ = 1;
putWord(trkdata[Trk].zmd, p * 2);
trkdata[Trk].zmd += 2;
}
}
zms = skipSpc(zms);
if (*zms == ',') {
zms += 1;
} else {
break;
}
}
}
break;
case 'u': case 'U': /* @u */
/*OK*/ zms = setMMLatU(zms,trkdata,trkinf,target, 0);
break;
case 'v': case 'V': /* @v */
zms = makeZmdVolume(zms, trkdata, target, trkinf, 0);
break;
case 'w': case 'W': /* @w */
/*OK*/ zms = makeZmdTrackDelay(zms, trkdata, target, trkinf, cominf, 0);
break;
case 'x': case 'X': /* @x */
zms = makeZmdExclusive(zms, trkdata, target, 0);
break;
case 'y': case 'Y': /* @y */
zms = makeZmdSetNRPN(zms, trkdata, target);
break;
case 'z': case 'Z': /* @z */ /* thanks to Mamiya */
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
int i = 0 ;
DWORD z = trkinf[Trk].velou.var[0];
line = line_;
ld = ld_;
zms = getnum2(zms_, &tmpDWORD, &err);
/*zms = skipSpc(zms);*/
if (err < 0 && *zms != ',') {
*trkdata[Trk].zmd++ = 0xBE;
*trkdata[Trk].zmd++ = 0x00;
continue;
}
*trkdata[Trk].zmd++ = 0xE3;
line = line_;
ld = ld_;
zms = zms_ - 1 ;
do {
int r = 0 ;
zms = skipSpcCr(zms + 1);
if (*zms == '+' || *zms == '-') r = 1 ;
zms = getnum2(zms, &tmpDWORD, &err);
if (err < 0) {
*trkdata[Trk].zmd++ = -1 ;
} else if (r) {
z += tmpDWORD ;
z = (z < 0) ? z : ((z > 127) ? 127 : z) ;
*trkdata[Trk].zmd++ = z;
} else {
*trkdata[Trk].zmd++ = z = tmpDWORD;
}
/*zms = skipSpc(zms);*/
} while (++i < 8 && *zms == ',') ;
while (i++ < 8) *trkdata[Trk].zmd++ = -1;
if (*zms == ',') {
zmserror("@z: too many ','.",line,linebuf_,zms,2,1);
zms++ ;
}
}
break;
/* (BEGIN FM/ADPCMsupport by Mamiya */
case 't': case 'T': /* @t */
zms = makeZmdTempo(zms, trkdata, target, 2);
#ifdef A
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
BYTE rel = 0;
line = line_;
ld = ld_;
zms = skipSpcCr(zms_);
if (*zms == '+') {
rel = 1;
} else if (*zms == '-') {
rel = -1;
}
zms = getnum2(zms, &tmpDWORD, &err);
if (err < 0) {
zmserror("@t must be followed to its parameter.",line_,linebuf_,zms_,0,1);
} else {
if (!rel) {
*trkdata[Trk].zmd++ = 0xC1;
} else if (tmpDWORD < 0) {
*trkdata[Trk].zmd++ = 0xC2;
tmpDWORD = -tmpDWORD;
} else {
*trkdata[Trk].zmd++ = 0xC2;
}
putWord(trkdata[Trk].zmd, tmpDWORD);
trkdata[Trk].zmd += 2;
zmserror("@t will be ignored by many drivers.",line_,linebuf_,zms_ - 1,3,1);
}
}
#endif
break;
case 'o': case 'O': /* @o */
zms = getnum2(zms, &tmpDWORD, &err);
for (trk = 0; target[trk] >= 0; trk++) {
if (err < 0) {
*trkdata[target[trk]].zmd++ = 0x82;
} else {
*trkdata[target[trk]].zmd++ = 0xA5;
*trkdata[target[trk]].zmd++ = 128 + tmpDWORD ;
}
}
break;
case 'f': case 'F': /* @f */
zms = getnum2(zms, &tmpDWORD, &err);
if (err < 0) {
zmserror("@f can't omit its parameter.",line_,linebuf_,zms_,0,1);
}
for (trk = 0; target[trk] >= 0; trk++) {
*trkdata[target[trk]].zmd++ = 0xA9;
*trkdata[target[trk]].zmd++ = tmpDWORD ;
}
break;
/* FM/ADPCMsupport by Mamiya END) */
default:
zms = makeZmdProgramChange(--zms, trkdata, target);
break;
}
return zms;
}
UBYTE *makeZmdLoop1(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf)
{ /* |: |n | */
int trk;
UBYTE *zms_ = zms;
DWORD line_ = line;
LINEDATA *ld_ = ld;
char *linebuf_ = linebuf;
switch (*zms++) {
case '|':
if (*zms == ':') { /* |: */
/*OK*/ DWORD looptime;
int err;
zms = getnum2(++zms,&looptime,&err);
if (err >= 0 && looptime <= 0) {
zmserror("illegal looptime.",line_,linebuf_,zms_,0,1);
}
line_ = line;
ld_ = ld;
if (err < 0) {
looptime = 2;
}
for (trk = 0; target[trk] >= 0; trk++) {
int Trk = target[trk];
do {
char s[32];
sprintf(s,"trkinf[%d].l->next");
line = line_;
ld = ld_;
recoverSpecialVelocity(trkinf, Trk);
if (trkinf[Trk].l->loopmode < 0) { /* |n .. :| .. |: */
/* loopmode<0 means "|n ..:| parsed" */
/* new loop begins */
trkinf[Trk].l = trkinf[Trk].l->prev;
efree(trkinf[Trk].l->next,"trkinf[Trk].l->next");
/* trkinf[Trk].l->next = NULL; */
}
*trkdata[Trk].zmd++ = 0xCD;
trkinf[Trk].l->next = (LOOPDATA*)emalloc(sizeof(LOOPDATA) * 1,s);
trkinf[Trk].l->next->prev = trkinf[Trk].l;
trkinf[Trk].l = trkinf[Trk].l->next;
trkinf[Trk].l->next = (LOOPDATA*)NULL;
trkinf[Trk].l->loopstart = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
trkinf[Trk].l->loopskip = 0; /* (UBYTE*)NULL; */
putWord(trkdata[Trk].zmd, looptime - 1);
trkinf[Trk].l->looptime = looptime;
trkinf[Trk].l->looptime2 = 0;
putWord(trkdata[Trk].zmd + 2, 0);
trkdata[Trk].zmd += 4;
trkinf[Trk].l->loopmode = 0;
trkinf[Trk].l->totalstart = trkinf[Trk].total;
trkinf[Trk].l->totalmode = -1;
/* totalmode: -1= no |,|n 0 = | 1 = |n */
} while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
}
} else { /* |... */
DWORD tmpDWORD;
int err;
for (trk = 0; target[trk] >= 0; trk++) {
int Trk = target[trk];
do {
if (trkinf[Trk].l->totalmode == -1) {
trkinf[Trk].total +=
(trkinf[Trk].total - trkinf[Trk].l->totalstart) *
(trkinf[Trk].l->looptime - 1);
}
trkinf[Trk].l->totalstart = trkinf[Trk].total;
} while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
}
zms = getnum2(zms,&tmpDWORD,&err);
line = line_;
ld = ld_;
if (!err) { /* |n */
if (tmpDWORD <= 0) {
zmserror("illegal looptime.",line_,linebuf_,zms_,0,1);
}
/*OK*/ for (trk = 0; target[trk] >= 0; trk++) {
int Trk = target[trk];
do {
line = line_;
ld = ld_;
if (tmpDWORD > trkinf[Trk].l->looptime) {
zmserror("n is too large in |n.",line_,linebuf_,zms_,0,1);
}
*trkdata[Trk].zmd++ = 0xD8;
putWord(trkdata[Trk].zmd, tmpDWORD - 1);
trkdata[Trk].zmd += 2;
if (trkinf[Trk].l->loopskip) {
zmserror("illegal |n.",line_,linebuf_,zms_,0,1);
} else {
const DWORD ls = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
trkinf[Trk].l->loopmode = tmpDWORD;
putDword(trkdata[Trk].zmd, ls - trkinf[Trk].l->loopstart + 2);
trkdata[Trk].zmd += 4;
trkinf[Trk].l->loopskip = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
putDword(trkdata[Trk].zmd, 0);
trkdata[Trk].zmd += 4;
}
trkinf[Trk].l->totalmode = 1;
} while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
}
} else if (err < 0) { /* | */
/*OK*/ for (trk = 0; target[trk] >= 0; trk++) {
int Trk = target[trk];
do {
line = line_;
ld = ld_;
if (trkinf[Trk].l->prev == NULL ||
(trkinf[Trk].l->prev->prev == NULL && trkinf[Trk].l->loopmode < 0) ) {
zmserror("illegal |.",line_,linebuf_,zms_,3,1);
} else {
*trkdata[Trk].zmd++ = 0xD9;
if (trkinf[Trk].l->loopskip) {
zmserror("illegal |.",line_,linebuf_,zms_,0,1);
} else {
const DWORD ls = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
/* putWord(trkdata[Trk].zmd, 0); */
putDword(trkdata[Trk].zmd, ls - trkinf[Trk].l->loopstart + 2);
trkdata[Trk].zmd += 4;
trkinf[Trk].l->loopskip = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
putDword(trkdata[Trk].zmd, 0);
trkdata[Trk].zmd += 4;
trkinf[Trk].l->loopmode = 0;
}
}
trkinf[Trk].l->totalmode = 0;
} while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
}
}
}
break;
case ':':
if (*zms++ == '|') { /* :| */
/*tenuki*/ for (trk = 0; target[trk] >= 0; trk++) {
int Trk = target[trk];
do {
DWORD tmpDWORD;
int i, level = 0;
/* UBYTE *ls; */
DWORD ls;
switch (trkinf[Trk].l->totalmode) {
case -1: /* w/o | |n */
trkinf[Trk].total +=
(trkinf[Trk].total - trkinf[Trk].l->totalstart) *
(trkinf[Trk].l->looptime - 1);
break;
case 0: /* w/ | */
trkinf[Trk].total +=
(trkinf[Trk].total - trkinf[Trk].l->totalstart) *
(trkinf[Trk].l->looptime - 2);
break;
case 1: /* w/ |n */
/* no need to add any values */
break;
}
line = line_;
ld = ld_;
if (trkinf[Trk].l->prev == NULL || (trkinf[Trk].l->prev->prev == NULL && trkinf[Trk].l->loopmode < 0) ) {
zmserror("too many :| .",line_,linebuf_,zms_,0,1);
}
ls = (trkinf[Trk].l->loopmode < 0)? /* |n .. :| :| ? */
trkinf[Trk].l->prev->loopstart :
trkinf[Trk].l->loopstart;
*trkdata[Trk].zmd++ = 0xCE;
trkdata[Trk].zmd += 4;
/* tmpDWORD = trkdata[Trk].zmd - ls; */ /* trkinf[Trk].l->loopstart; */
tmpDWORD = trkdata[Trk].zmd - trkdata[Trk].zmdbuf - ls;
/* trkinf[Trk].l->loopstart; */
/* trkdata[Trk].zmd -= 2; */
putDword(trkdata[Trk].zmd - 4, tmpDWORD);
/* trkdata[Trk].zmd += 2; */
if (trkinf[Trk].l->loopskip) { /* exist | or |n ? */
putDword(trkdata[Trk].zmdbuf + trkinf[Trk].l->loopskip ,
(trkdata[Trk].zmd - trkdata[Trk].zmdbuf) - trkinf[Trk].l->loopskip - 4);
trkinf[Trk].l->loopskip = 0;
if (trkinf[Trk].l->loopmode) { /* |n? */
level = 0; /* |n ... :| */
/* add v0.65 */ if (++trkinf[Trk].l->looptime2 == trkinf[Trk].l->looptime) {
level = 1;
}
} else { /* | ... :| */
level = 1;
}
} else if (trkinf[Trk].l->loopmode == 0) { /* normal loop :| */
level = 1;
} else if (trkinf[Trk].l->loopmode < 0) { /* |n .. :| .. :| */
level = 2;
}
for (i = 0; i < level; i++) {
trkinf[Trk].l = trkinf[Trk].l->prev;
efree(trkinf[Trk].l->next,"trkinf[Trk].l->next");
trkinf[Trk].l->next = NULL;
}
/* loop is end if it's not | or |n after |n... :| */
if (level == 0) { /* |n .. :| */
trkinf[Trk].l->loopmode = -trkinf[Trk].l->loopmode;
} else { /* lev == 1: normal :| */
/* trkinf[Trk].l->loopmode = 0; */ /* lev == 2: |n ... :| .. :| */
}
} while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
}
} else {
zmserror("SYNTAX ERROR",line_,linebuf_,zms_,0,1);
}
break;
}
return zms;
}
UBYTE *makeZmdEigDepthSub(UBYTE *zms,
VELOETCVAR *vv, BYTE *pos,BYTE *num,BYTE supplementmode)
{
int i, paras;
VELOETCVAR v[17];
const BYTE lastvpos = *num;
*pos = 0;
/* zms = getpara(zms, v, ¶s); */
zms = getpara(zms, v, ¶s, 0);
if (v[0].relflg[0] == 2) { /* omit 1st parameter */
if (paras) { /* continues... */
vv[0].var[0] = (supplementmode)? vv[lastvpos].var[0] : 0;
} else { /* that's all */
*pos = *num = 0;
}
} else { /* 1st parameter is there */
WORD velo = v[0].var[0];
#ifdef A
if (v[0].relflg[0] == 1 && supplementmode) { /* relative */
velo += vv[lastvpos].var[0];
}
#endif
/*
printf("[V=%d]",velo);
*/
vv[0].var[0] = velo;
}
vv[0].relflg[0] = v[0].relflg[0];
for (i = 1; i < paras; i++) { /* next... */
if (v[i].relflg[0] == 2) { /* omit Nth parameter */
vv[i].var[0] = (supplementmode)? vv[i - 1].var[0] : 0;
} else {
WORD velo = v[i].var[0];
if (v[i].relflg[0] == 1 && supplementmode) {
velo += vv[i - 1].var[0];
}
/*
printf("[V=%d]",velo);
*/
vv[i].var[0] = velo;
}
vv[i].relflg[0] = v[i].relflg[0];
}
*num = paras;
return zms;
}
UBYTE *makeZmdVeloSeq(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf)
{
int trk;
char *zms_ = zms;
DWORD line_ = line;
LINEDATA *ld_ = ld;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
int i, paras;
VELOETCVAR *v;
const BYTE lastvpos = trkinf[Trk].veloznum - 1;
const VELOETCVAR lastv = (lastvpos == -1) ? trkinf[Trk].velou : trkinf[Trk].velocity[lastvpos];
line = line_;
ld = ld_;
zms = getvpara(zms_, &v, ¶s);
trkinf[Trk].velozpos = 0;
trkinf[Trk].veloseqsw = 1;
if (paras) {
char s[32];
sprintf(s,"trkinf[%d].velocity",Trk);
trkinf[Trk].velocity = (VELOETCVAR*)erealloc(trkinf[Trk].velocity, sizeof(VELOETCVAR) * paras,s);
trkinf[Trk].veloznum = paras;
for (i = 0; i < paras; i++) {
if (v[i].relflg[0] == 2) { /* omit the 1st/Xth value */
if (i > 0) {
trkinf[Trk].velocity[i].var[0] = 0x80;
/* trkinf[Trk].veloz[i - 1].var[0]; */
trkinf[Trk].velocity[i].var[1] = /* 0x80; */
trkinf[Trk].velocity[i - 1].var[1];
} else {
trkinf[Trk].velocity[i] = lastv;
}
} else { /* 1st/Xth value is there */
WORD velo = v[i].var[0];
if (v[i].relflg[0] == 1) {
if (i > 0) {
velo += trkinf[Trk].velocity[i - 1].var[0];
} else {
velo += lastv.var[0];
}
if (velo > 127) {
velo = 127;
} else if (velo < 0) {
velo = 0;
}
}
trkinf[Trk].velocity[i].var[0] = velo;
trkinf[Trk].velocity[i].var[1] = v[i].var[1];
/* printf("[V=%d]",velo); */
}
}
/* if (paras) { */
/*trkinf[Trk].veloseqsw = 1; */
if (paras) {
trkinf[Trk].veloznum = paras;
}
if (paras == 1) {
int velo = trkinf[Trk].velocity[0].var[0];
const int r = trkinf[Trk].velocity[0].var[1];
trkinf[Trk].velou.var[0] = velo;
trkinf[Trk].velou.var[1] = r;
if (r) {
velo += rand2(r);
}
velo += trkinf[Trk].veloofst;
if (velo > 127) {
velo = 127;
} else if (velo < 0) {
velo = 0;
}
*trkdata[Trk].zmd++ = 0x93;
*trkdata[Trk].zmd++ = velo;
}
/* } */
}
setVelocitySequenceMode(trkinf,Trk,(paras > 1));
efree(v,"v");
/* trkinf[Trk].veloz[0].relflg[0] = 0; */
/* zmserror("velocity sequence error",line,linebuf,zms,0,1); */
}
return zms;
}
UBYTE *makeZmdQuantize(UBYTE *zms, int mode, const BYTE target[],
TRKINF *trkinf)
{
int trk;
char *zms_ = zms;
DWORD line_ = line;
LINEDATA *ld_ = ld;
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
int i, paras;
VELOETCVAR *v;
const BYTE lastvpos = trkinf[Trk].quantizenum - 1;
const VELOETCVAR lastv = (lastvpos == -1) ? trkinf[Trk].quantize[0] : trkinf[Trk].quantize[lastvpos];
char s[32];
sprintf(s,"trkinf[%d].quantize",Trk);
line = line_;
ld = ld_;
/* zms = getpara(zms, v, ¶s); */
zms = getvpara(zms_, &v, ¶s);
trkinf[Trk].quantizepos = 0;
if (paras == 0) {
paras = 1;
}
trkinf[Trk].quantize = (VELOETCVAR*)erealloc(trkinf[Trk].quantize, sizeof(VELOETCVAR) * paras,s);
trkinf[Trk].quantizenum = paras;
for (i = 0; i < paras; i++) { /* next one... */
if (v[i].relflg[0] == 2) { /* omit Nth parameter */
if (i == 0) {
trkinf[Trk].quantize[0] = lastv;
} else {
trkinf[Trk].quantize[i] = trkinf[Trk].quantize[i - 1];
}
} else {
trkinf[Trk].quantize[i] = v[i];
if (mode == 0) { /* @q... */
trkinf[Trk].quantize[i].relflg[0] = 1;
} else { /* q... */
if (trkinf[Trk].quantize[i].var[0] < 0) {
trkinf[Trk].quantize[i].var[0] = -trkinf[Trk].quantize[i].var[0];
switch (mode) {
case 1: /* zmc2old -v1.16 */
trkinf[Trk].quantize[i].relflg[0] = 3;
break;
case 2: /* zmc2 v1.17 */
break;
case 3: /* V3 compatible */
if (trkinf[Trk].quantize[i].relflg[0] == 3) { /* *n */
trkinf[Trk].quantize[i].relflg[0] = 1;
} else {
trkinf[Trk].quantize[i].relflg[0] = 0;
trkinf[Trk].quantize[i].var[0] += 8;
}
break;
}
}
}
}
}
if (paras > 1) {
zmserror("quantize sequence can use only for zmc2.",line,linebuf,zms,4,1);
}
efree(v,"v");
}
return zms;
}
UBYTE *makeZmdManyParas(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
DWORD line_,char *linebuf_,
UBYTE com, UBYTE omitcode,BYTE maxparas,
BYTE parabytes,BYTE omitflg,
char *errmes1, char *errmes2,char *errmes3)
{
VELOETCVAR v[17];
UBYTE *zms_ = zms;
int tmpINT;
zms = getpara(zms,v,&tmpINT,0);
if (tmpINT > maxparas || (!omitflg && tmpINT != maxparas)) {
zmserror(errmes1,line_,linebuf_,zms_,0,1);
} else {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
int i;
const int Trk = target[trk];
*trkdata[Trk].zmd++ = com;
for (i = 0; i < tmpINT; i++) {
if (v[i].relflg[0] == 2) { /* omit Nth parameter */
if (omitflg) {
*trkdata[Trk].zmd++ = omitcode;
if (parabytes == 2) {
*trkdata[Trk].zmd++ = omitcode;
}
} else {
zmserror(errmes3,line_,linebuf_,zms_,0,1);
}
} else {
if (v[i].relflg[0] == 1) { /* relative */
zmserror(errmes2,line_,linebuf_,zms_,0,1);
} else {
if (parabytes == 2) {
putWord(trkdata[Trk].zmd, v[i].var[0]);
trkdata[Trk].zmd += 2;
} else {
*trkdata[Trk].zmd++ = v[i].var[0];
}
}
}
}
for (i = tmpINT; i < maxparas; i++) {
*trkdata[Trk].zmd++ = omitcode;
if (parabytes == 2) {
*trkdata[Trk].zmd++ = omitcode;
}
}
}
}
return zms;
}
/* omit flag byte(d0,d1,d2,...) supported */
UBYTE *makeZmdManyParas2(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
DWORD line_,char *linebuf_,
UBYTE com, BYTE maxparas,
const BYTE parabytes[],BYTE omitflg,BYTE ARCCno,
int space, int times, const int mustover0,
char *errmes1, char *errmes2,char *errmes3)
{
VELOETCVAR v[17];
UBYTE *zms_ = zms;
int tmpINT;
UWORD ob = 0;
zms = getpara(zms,v,&tmpINT,mustover0);
if (tmpINT > maxparas || (!omitflg && tmpINT != maxparas)) {
zmserror(errmes1,line_,linebuf_,zms_,0,1);
} else {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
int i;
const int Trk = target[trk];
UBYTE *obp;
*trkdata[Trk].zmd++ = com;
if (ARCCno >= 0) {
*trkdata[Trk].zmd++ = ARCCno * 2;
}
for (i = 0; i < space; i++) {
trkdata[Trk].zmd++;
}
obp = trkdata[Trk].zmd++; /* for omit flag byte */
if (maxparas > 8) {
trkdata[Trk].zmd++;
}
for (i = 0; i < tmpINT; i++) {
ob >>= 1;
if (v[i].relflg[0] == 2) { /* omit Nth parameter */
if (omitflg) {
if (maxparas > 8) {
ob &= 0xFF;
} else {
ob &= 0x7F;
}
} else {
zmserror(errmes3,line_,linebuf_,zms_,0,1);
}
} else {
if (maxparas > 8) {
ob |= 0x100;
} else {
ob |= 0x80;
}
if (v[i].relflg[0] == 1) { /* relative */
zmserror(errmes2,line_,linebuf_,zms_,0,1);
} else {
if (parabytes[i] == 1) {
*trkdata[Trk].zmd++ = v[i].var[0] * times;
} else if (parabytes[i] == 2) {
putWord(trkdata[Trk].zmd, v[i].var[0] * times);
trkdata[Trk].zmd += 2;
} else {
trkdata[Trk].zmd +=
putZvar(trkdata[Trk].zmd, v[i].var[0] * times);
}
}
}
}
for (i = tmpINT; i < 8; i++) {
ob >>= 1;
if (maxparas > 8) {
ob &= 0xFF;
} else {
ob &= 0x7F;
}
}
if (maxparas > 8) {
ob >>= 1;
putWord(obp, ob);
} else {
*obp = ob;
}
}
}
return zms;
}
/* omit flag byte(d7,d6,d5,...) supported (for ARCC) */
UBYTE *makeZmdManyParas2A(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
DWORD line_,char *linebuf_,
UBYTE com, BYTE maxparas,
const BYTE parabytes[],BYTE omitflg, BYTE ARCCno,
int mode,
char *errmes1, char *errmes2,char *errmes3)
{
VELOETCVAR v[17];
UBYTE *zms_ = zms;
int tmpINT;
UBYTE ob = 0;
zms = getpara(zms,v,&tmpINT,0);
if (tmpINT > maxparas || (!omitflg && tmpINT != maxparas)) {
zmserror(errmes1,line_,linebuf_,zms_,0,1);
} else {
int trk;
for (trk = 0; target[trk] >= 0; trk++) {
int i;
const int Trk = target[trk];
UBYTE *obp = trkdata[Trk].zmd + 2;
*trkdata[Trk].zmd++ = com;
*trkdata[Trk].zmd++ = ARCCno * 2;
trkdata[Trk].zmd++; /* for omit flag byte */
for (i = 0; i < tmpINT; i++) {
ob <<= 1;
if (v[i].relflg[0] == 2) { /* omit Nth parameter */
if (omitflg) {
ob &= 0xFE;
} else {
zmserror(errmes3,line_,linebuf_,zms_,0,1);
}
} else {
ob++;
if (v[i].relflg[0] == 1) { /* relative */
zmserror(errmes2,line_,linebuf_,zms_,0,1);
} else {
if (parabytes[i] == 1) {
*trkdata[Trk].zmd++ = v[i].var[0];
} else if (parabytes[i] == 2) {
putWord(trkdata[Trk].zmd, v[i].var[0]);
trkdata[Trk].zmd += 2;
} else {
trkdata[Trk].zmd +=
putZvar(trkdata[Trk].zmd, v[i].var[0]);
}
}
}
}
for (i = tmpINT; i < 8; i++) {
ob <<= 1;
ob &= 0xFE;
}
*obp = ob;
if (mode >= 0) {
ob >>= 1;
if (mode > 0) {
ob |= 0x80;
}
*obp = ob;
}
}
}
return zms;
}
UBYTE *makeZmdChord(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf,char extmode,COMMONINF *cominf)
{
int trk;
UBYTE *zms_ = zms;
DWORD line_ = line;
UBYTE *linebuf_ = linebuf;
LINEDATA *ld_ = ld;
const char sepchr = (extmode)? '\"' : '\'';
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
BYTE note[9];
VELOETCVAR v[9];
UWORD step_; /* = trkinf[Trk].Step; */
UWORD gate_; /* = getGate1(target,trkinf,trk,step_); */
UWORD gate0;
WORD delay = trkinf[Trk].cdelay;
WORD ptime = trkinf[Trk].ptime;
int i,notes;
BYTE *qpos = &(trkinf[Trk].quantizepos);
/* const BYTE vnum = trkinf[Trk].veloznum; */
/* const BYTE oct = trkinf[Trk].octave; */
line = line_;
ld = ld_;
zms = makePortChord(zms_,Trk,trkinf,cominf,
sepchr,0,v,note,¬es,&step_,&gate_, &gate0,
&delay, &ptime);
/* trkinf[Trk].octave = oct; */ /* restore octave */
incrementStepCounters(&trkinf[Trk], step_);
/* fprintf(stderr,"[G=%d]",gate0); */
/*
{
int i = 0;
fprintf(stderr,"\n[");
for (i = 0; i < notes; i++) {
fprintf(stderr,"%.2x ",note[i]);
}
fprintf(stderr,"]");
}
*/
trkinf[Trk].cdelay = delay;
/* trkinf[Trk].ptime = ptime; */
if (delay < 0) { /* reverse chord pattern */
int i;
for (i = 0; i < notes / 2; i++) {
BYTE temp = note[i];
note[i] = note[notes - i - 1];
note[notes - i - 1] = temp;
}
delay = -delay;
zmserror("delay under 0 can use only for zmc3.",line_,linebuf_,zms,4,1);
}
if (delay) { /* check delay parameter */
const DWORD delayall = (notes - 1) * (delay - 1);
if (delayall > step_) {
zmserror("delay parameter for the chord is too large (for steptime).",line_,linebuf_,zms_,2,1);
} else if (delayall > gate_) {
zmserror("delay parameter for the chord is too large (for gatetime).",line_,linebuf_,zms_,3,1);
}
}
/* 和音でタイになるときはgate=0xFFFFになる
* タイの先が続く音の場合のみ0xFFFF, さもなくば0x8000
* 例: 'ce'&'eg'なら、cは0x8000, eは0xFFFF
*
* →とりあえず0x8000で埋めておいて、後で必要なら0xFFFFに置換する
*/
if (gate_ == 0xFFFF) {
gate_ = 0x8000;
}
{
WORD velo = 0;
BYTE relvelo = 0;
int i;
#ifdef AA
/* del 0.74 */
if (!extmode) {
velo = setVelo0(trkdata,Trk,v[0],&relvelo,trkinf,cominf,step_);
if (trkinf[Trk].veloseqsw) { /* add v0.74 */
vSeqLoopChk(Trk,trkinf);
}
}
#endif
{ /* add v0.74: clear chord-used flag */
CHKCHORD *c_last, *c = trkinf[Trk].c;
do {
c->isclosed = 0;
c_last = c;
c = c->next;
} while (c);
}
for (i = 0; i < notes; i++) {
int usedchordtone = 0;
CHKCHORD *c_last = NULL, *c = trkinf[Trk].c;
/* BYTE relvelo = 0; */
/* set "velocity sequence" or "special velocity" */
if (i == notes - 1) {
if (gate_ <= 0) {
gate_ = 1;
}
}
velo = setVelo0(trkdata,Trk,v[i],&relvelo,trkinf,cominf,step_);
/* vSeqLoopChk(Trk,trkinf); */ /* velo.seq loop check */
if (extmode) {
if (trkinf[Trk].veloseqsw) { /* add v0.74 */
vSeqLoopChk(Trk,trkinf);
}
}
/* fprintf(stderr,"[%d:V=%d/%d/%d]",i,v[i].var[0],v[i].relflg[0],velo); */
do { /* add 0.62: scan the chord before */
if (c->note == note[i]) { /* if there is tie-d tone before */
rewriteGateinChord(trkdata, trkinf, Trk, c, 0xFFFF);
c->gatepos = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
usedchordtone = 1;
/* if (gate_ != 0x8000) { */ /* add v0.74 */
c->isclosed = 1;
/* } */
break;
}
c_last = c;
c = c->next;
} while (c);
if (!usedchordtone && gate_ == 0x8000) { /* no chord before */
DWORD gatepos = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
c = c_last;
c = addNextChkChord(c, note[i], gatepos, gate0);
}
/* set tonename with "*0&" */
{
UWORD d = (i < notes - 1)? delay : step_;
/* const UWORD g = (gate_ == 0x8000)? 0x8000 + step_ : gate_; */
const UWORD g = gate_;
const int pflg = (i == notes - 1)? 0 : 2; /* last note? */
/* fprintf(stderr,"g=%d\n",g); */
zms = setTie2(zms,trkdata,Trk,trkinf,note[i],
d,g,relvelo,pflg,velo);
}
if (i < notes - 1) {
step_ -= delay;
if (gate_ != 0xFFFF && gate_ != 0x8000) {
gate_ -= delay;
}
}
}
#ifdef A
if (gate_ <= 0) {
gate_ = 1;
}
if (extmode) {
velo = setVelo0(trkdata,Trk,v[notes - 1],&relvelo,trkinf,cominf,step_);
if (trkinf[Trk].veloseqsw) { /* add v0.74 */
vSeqLoopChk(Trk,trkinf);
}
}
/* vSeqLoopChk(Trk,trkinf); */ /* velo.seq loop check */
/*tooslow*/ if (gate_ == 0x8000) {
zms = setTie2(zms,trkdata,Trk,trkinf,note[notes - 1],
step_,0x8000 + step_,relvelo,0,velo);
} else {
zms = setTie2(zms,trkdata,Trk,trkinf,note[notes - 1],
step_, gate_ ,relvelo,0,velo);
}
#endif
{ /* add v0.74: is tied-tone used?
* 相当処理がmakeZmdNoteやポルタメントには入っていないので
* 今後フォローが必要
*/
CHKCHORD *c_last, *c = trkinf[Trk].c;
do {
if (!c->isclosed && c->note != -1) {
CHKCHORD *c_kill = c;
rewriteGateinChord(trkdata, trkinf, Trk, c, 0x8000 + c->gate);
/* fprintf(stderr,"{%p %p}",c->prev,c->next); */
/*fprintf(stderr,"[%d]",c->note - 0x3c);*/
c = killChord(c); /* free 'c' */
}
c_last = c;
c = c->next;
} while (c);
}
if (gate_ != 0x8000) { /* non tie */
freeAllChord(trkinf[Trk].c);
}
/* fprintf(stderr,"(t=%d, g=%d)",trkinf[Trk].total,gate_); */
}
if (++*qpos >= trkinf[Trk].quantizenum) {
*qpos = 0;
}
}
/*
* { ... 'ceg'}&
* なんてのを正しく検出できない(元祖V3も同様)ので、
* 先読みをかました方がいいかも
*/
return zms;
}
CHKCHORD *addNextChkChord(CHKCHORD *c, BYTE note, DWORD gatepos, DWORD gate)
{
c->next = emalloc(sizeof(CHKCHORD) * 1,"c->next");
c->next->prev = c;
c = c->next;
c->next = NULL;
c->note = note;
c->gatepos = gatepos;
c->isclosed = 1;
c->gate = gate;
/* fprintf(stderr,"(%.2x: total=%d)",c->note,c->total); */
return c;
}
void rewriteGateinChord(TRKCHINF *trkdata, TRKINF *trkinf,
int Trk,CHKCHORD *c, UWORD gate)
{
UBYTE *CHORDGATEPOS = getChordGatePos(trkdata[Trk].zmdbuf,
c->gatepos, trkinf[Trk].renpnotes);
/*
fprintf(stderr,"{%.2x %.2x %.2x %.2x %.2x %.2x}",
*(CHORDGATEPOS - 2),
*(CHORDGATEPOS - 1),
*(CHORDGATEPOS ),
*(CHORDGATEPOS + 1),
*(CHORDGATEPOS + 2),
*(CHORDGATEPOS +3));
*/
/*fprintf(stderr,"[rewrite %x(%x):%X]",
CHORDGATEPOS - trkdata[Trk].zmdbuf,trkdata[Trk].zmdbuf[CHORDGATEPOS - trkdata[Trk].zmdbuf-2],gate);
*/
putWord(CHORDGATEPOS, gate);
}
CHKCHORD *killChord(CHKCHORD *c)
{
CHKCHORD *c_kill = c;
c->prev->next = c->next;
if (c->next) {
c->next->prev = c->prev;
}
c = c->prev;
efree(c_kill,"c");
return c;
}
int checkCommonCommand(UBYTE *zms_,int notes,BYTE note[],UWORD step_,
DWORD line_,char *linebuf_, COMMONINF *cominf)
{
int ret = 0;
if (notes == 1 && (note[0] % 12) == 2) {
if (step_ == 0 || step_ == cominf->div) { /* (d0) || (d1) */
cominf->debug = (step_)? 1 : 0;
ret = 1;
} else {
zmserror("portament requires 2 tones.",line_,linebuf_,zms_,0,1);
}
} else {
zmserror("portament requires 2 tones.",line_,linebuf_,zms_,0,1);
}
return ret;
}
#ifdef AAA
UBYTE *makeZmdChordStr(UBYTE *zms, const int Trk,
TRKINF *trkinf,COMMONINF *cominf,
const UBYTE endchar,
VELOETCVAR v[],BYTE note[],int *notes,
UWORD *step_, UWORD *gate_,WORD *delay, WORD *ptime)
{
/* const int Trk = target[trk]; */
UWORD step;
int i,err,steps = 0;
int beforeOctave = trkinf[Trk].octave;
DWORD tmpDWORD;
const UWORD Step = trkinf[Trk].Step;
{
/* */
/* 基本はmajor code(C = 0,4,7)
*
* 1)音階直後にmがきたら,第2paraを3にする (短3度)
* dimが来たら,(0,4,7)を(0,3,6,9)にする(減3和音+減7度)
* sus4が来たら,第2paraを5にする (メジャートライアド+短7度-3度+完全4度)
*
* 2)以降Δ7,M7,maj7が来たら,長7度(11)を追加する (長7度)
* ()なしで数値xが来たら,短x度を追加する (短7度など)
* (#5),(+5),augが来る || [n+]だったら,第3paraを8にする
* (♭5),(-5)が来る || [n-]だったら,第3paraを6にする
*
* Bm7(-5)を Bφ (減3和音+短7度(m7))
*/
/* major code */
* { 0, 4, 7, -1 }, /* C */
* { 0, 4, 7, 9, -1 }, /* C6 */
* { 0, 4, 7, 11, -1 }, /* CΔ7 CM7 Cmaj7 */
* { 0, 4, 8, -1 }, /* C(#5) [C+] Caug */
* { 0, 4, 6, -1 }, /* C(-5) [C-] */ /* [C-] */
* { 0, 5, 7, -1 }, /* Csus4 */
/* minor code */
* { 0, 3, 7, -1 }, /* Cm [C-] */ /* [C-] */
* { 0, 3, 7, 9, -1 }, /* Cm6 */
* { 0, 3, 7, 11, -1 }, /* CmΔ7 */
/* minor 7th code */
* { 0, 3, 7, 10, -1 }, /* Cm7 */
/* minor 7th (♭5) code */
* { 0, 3, 6, 10, -1 }, /* Cm7(-5) */
/* Dominant 7th code */
* { 0, 4, 7, 10, -1 }, /* C7 */
* { 0, 4, 8, 10, -1 }, /* C7(#5) */
* { 0, 4, 6, 10, -1 }, /* C7(-5) */
* { 0, 5, 7, 10, -1 }, /* C7sus4 */
/* diminish code */
* { 0, 3, 6, 9, -1 }, /* Cdim */
┌──────────┬────────────────────┐
│コード表記 │コード名 │
├──────────┼────────────────────┤
@ │A │A │
@ │A6 │Aシックス │
@ │AMaj7 │Aメジャー・セブンス │
│AMaj9 │Aメジャー・ナインス │
│A69 │Aシックス・ナインス │
│Aaug, A +5 │Aオーグメント │
@ │A7 │Aセブンス │
│A9 │Aナインス │
│A11 │Aイレブンス │
│A13 │Aサーティーンス │
│A7+5, Aaug7 │Aオーグメント・セブンス │
│A9+5, A9aug │Aオーグメント・ナインス │
│A7+9 │Aセブン・シャープド・ナインス │
│A +11 │Aシャープド・イレブンス │
│Adim7 │Aディミニッシュド・セブンス │
│Adimj7 │Aディミニッシュド・メジャー・セブンス │
│Adim9 │Aディミニッシュド・ナインス │
@ │Asus4 │Aサスペンディッド・フォー │
│ │ │
│Am │Aマイナー │
│Am6 │Aマイナー・シックス │
│AmMaj7 │Aマイナー・メジャー・セブンス │
│AmMaj9 │Aマイナー・メジャー・ナインス │
│Am69 │Aマイナー・シックス・ナインス │
│Aalt, A -5 │Aアルタード │
│Am7 │Aマイナー・セブンス │
│Am9 │Aマイナー・ナインス │
│Am11 │Aマイナー・イレブンス │
│Am13 │Aマイナー・サーティーンス │
│A7-5, Aalt7 │Aアルタード・セブンス │
│A9-5, A9alt │Aアルタード・ナインス │
│A7-9 │Aセブン・フラッテッド・ナインス │
│A13(+11), A13(#11)│Aサーティーンス・シャープド・イレブンス│
│Am7-5 │Aアルタード・マイナー・セブンス │
│Am9-5 │Aアルタード・マイナー・セブンス │
│Am11-5 │Aアルタード・マイナー・イレブンス │
│A7sus4 │Aセブンス・サスペンディッド・フォー │
└──────────┴────────────────────┘
#endif